//
//  MYGResumeShareCell.swift
//  MYDoctor
//
//  Created by 小火科技 on 2024/4/24.
//

import UIKit
import QMUIKit

class MYGResumeShareCell: UITableViewCell {
    var editResumeInfBlock:(()->Void)?
    var isEN:Bool = false
    var type :String = ""
    var model:MYGResumeAllType? {
        didSet {
            guard let item = model else{return}
            Lab.isHidden = true
            
            if isEN == true {
                contentLab.text = item.en_content
            }else {
                contentLab.text = item.content
            }
//            switchBtn.isSelected = item.is_show == 1
            sLab.text = "详细内容"
            if (type == "Learnings"){//教育
                
                schoolLab.text = isEN ? item.en_school : item.school
                let yearStart = item.yearStart
                let yearEnd = item.yearEnd
                timeView.setTitle("\(yearStart)-\(yearEnd)", for: .normal)
                
                Lab.text = isEN ? item.en_teacher : item.teacher
                let education = isEN ? item.en_education : item.education
                let major = item.major
                workLab.text = "\(education)·\(major)"
                
                let ishow = education.isEmpty && major.isEmpty
                workLab.isHidden = ishow
                
                sLab.text = "在校经历"
                Lab.isHidden = false
                sLab.isHidden = item.experience.isEmpty
                contentLab.text = isEN ? item.en_experience : item.experience
                
            } else if (type == "Works"){//工作
                
                schoolLab.text = isEN ? item.en_company: item.company
                let yearStart = item.dateStart
                let yearEnd = item.dateEnd
                let job_duty = isEN ? item.en_job_duty : item.job_duty
                timeView.setTitle("\(job_duty)\(yearStart)-\(yearEnd)", for: .normal)
                workLab.text = item.jobType
                sLab.text = "工作内容"
                sLab.isHidden = item.content.isEmpty
                
            }else if (type == "GoodAt"){// 专业擅长
                schoolLab.text = ""
                let created_at = item.created_at
                timeView.setTitle("\(created_at)", for: .normal)
                workLab.text = ""
                
            }else if (type == "Honors"){//个人荣誉
          
                let yearStart = item.dateStart
                let yearEnd = item.dateEnd
                timeView.setTitle("\(yearStart)-\(yearEnd)", for: .normal)
                let jobType = ""
                workLab.text = jobType
                schoolLab.text = isEN ? item.en_title : item.title
            }else if (type == "Clinical"){//临床实验
                
                schoolLab.text = isEN ? item.en_title : item.title
                let yearStart = item.dateStart
                let yearEnd = item.dateEnd
                timeView.setTitle("\(yearStart)-\(yearEnd)", for: .normal)
                
                let jobType = ""
                workLab.text = jobType
                
            }else if (type == "Internship"){//实习经验
               
                schoolLab.text = isEN ? item.en_title : item.title
                let yearStart = item.dateStart
                let yearEnd = item.dateEnd
                timeView.setTitle("\(yearStart)-\(yearEnd)", for: .normal)

                let jobType = ""
                workLab.text = jobType
                
            } else if (type == "Publish"){//出版
              
                schoolLab.text = isEN ? item.en_title : item.title
                let yearStart = item.dateStart
                let yearEnd = item.dateEnd
                timeView.setTitle("\(yearStart)-\(yearEnd)", for: .normal)

                let jobType = ""
                workLab.text = jobType
                
            }else if (type == "Patent"){//获得专利
                
                schoolLab.text = isEN ? item.en_title : item.title
                let yearStart = item.dateStart
                let yearEnd = item.dateEnd
                timeView.setTitle("\(yearStart)-\(yearEnd)", for: .normal)

                let jobType = ""
                workLab.text = jobType
            } else if (type == "Custom"){//自定义模块
                
                //tipLab.text = item["name"] as! String
                schoolLab.text = isEN ? item.en_title : item.title
                let yearStart = item.dateStart
                let yearEnd = item.dateEnd
                timeView.setTitle("\(yearStart)-\(yearEnd)", for: .normal)

                let jobType = ""
                workLab.text = jobType
               
            }
            
            let text =  timeView.titleLabel?.text ??  ""
            let size: CGSize = getStringSize(font: .regular(14), viewSize:  CGSize(width: CGFloat(MAXFLOAT), height: SCALEWIDTH(20)), str:text )
            timeView.snp.updateConstraints { make in
                make.width.equalTo(size.width + 25)
            }
            
        }
        
    }
    
    @objc func editResumeInf(){
        editResumeInfBlock?()
    }
    @objc func clickSwitchBtn(_ sender:QMUIButton) {
        sender.isSelected = !sender.isSelected
        self.model!.is_show = sender.isSelected ? 1 : 0
        
    }
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        configUI()
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    // MARK: - UI
    private func configUI() {
        contentView.backgroundColor = .white
        
        //contentView.addSubview(tipLab)
        contentView.addSubview(schoolLab)
        contentView.addSubview(timeView)
        contentView.addSubview(workLab)
        contentView.addSubview(Lab)
        contentView.addSubview(sLab)
        contentView.addSubview(contentLab)
        contentView.addSubview(line)
        contentView.addSubview(switchBtn)
        
//        line1.snp.makeConstraints { make in
//            make.left.equalTo(17.5)
//            make.height.equalTo(15)
//            make.width.equalTo(3)
//            make.top.equalToSuperview().offset(17.5)
//        }
//
//        tipLab.snp.makeConstraints { make in
//            make.centerY.equalTo(line1)
//            make.left.equalTo(line1.snp.right).offset(13)
//            make.height.equalTo(25)
//        }
//
        
        timeView.snp.makeConstraints { make in
            make.centerY.equalTo(switchBtn)
            make.right.equalToSuperview().offset(-15)
            make.height.equalTo(20)
            make.width.equalTo(100)
        }
        
        switchBtn.snp.makeConstraints { make in
            make.left.equalTo(timeView.snp.left)
            make.top.equalToSuperview().offset(17.5)
            make.height.equalTo(23)
        }
        switchBtn.isHidden = true
        schoolLab.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(30)
            make.top.equalToSuperview().offset(17.5)
            make.right.equalTo(switchBtn.snp.left)
            make.height.equalTo(23)
        }
        
        workLab.snp.makeConstraints { make in
            make.left.equalTo(schoolLab)
            make.top.equalTo(switchBtn.snp.bottom).offset(5)
            make.height.equalTo(20)
        }
        
        Lab.snp.makeConstraints { make in
            make.centerY.top.height.equalTo(workLab)
            make.right.equalTo(timeView)
        }
        sLab.snp.makeConstraints { make in
            make.left.height.equalTo(schoolLab)
            make.top.equalTo(workLab.snp.bottom).offset(10.5)
        }
        contentLab.snp.makeConstraints { make in
            make.left.equalTo(schoolLab)
            make.right.equalTo(Lab)
            make.top.equalTo(sLab.snp.bottom)
            make.bottom.equalToSuperview()
        }
        
        line.snp.makeConstraints { make in
            make.left.right.equalToSuperview().inset(26)
            make.height.equalTo(0.5)
            make.bottom.equalToSuperview()
        }
        
    }
    
    private lazy var line1:UIView = {
        let line = UIView()
        line.backgroundColor = .rgba(73, 117, 236, 1)
        return line
        
    }()
    
    private lazy var tipLab:UILabel = {
        let tw = UILabel()
        tw.text = ""//教育经历"
        tw.textColor = .rgba(34, 34, 34, 1)
        tw.font = .medium(18)
        return tw
    }()
    
    private lazy var schoolLab:UILabel = {
        let tw = UILabel()
        tw.text = ""//北京大学"
        tw.textColor = .rgba(10, 10, 10, 1)
        tw.font = .regular(16)
        return tw
    }()
    
    
    private lazy var switchBtn: QMUIButton = {
        let btn = QMUIButton()
        btn.setImage(UIImage(named: "resume_Off"), for: .normal)
        btn.setImage(UIImage(named: "resume_On"), for: .selected)
        btn.setTitle("", for: .normal)
        btn.setTitleColor(.rgba(132, 132, 132, 1), for: .normal)
        btn.titleLabel?.font = .regular(14)
        btn.spacingBetweenImageAndTitle = 4
        btn.imagePosition = .right
        btn.addTarget(self, action: #selector(clickSwitchBtn(_:)), for: .touchUpInside)
        return btn
    }()
    
    private lazy var timeView: QMUIButton = {
        let btn = QMUIButton()
//        btn.setImage(UIImage(named: "re_next"), for: .normal)
//        btn.spacingBetweenImageAndTitle = 4
//        btn.imagePosition = .right
        btn.setTitle("", for: .normal)
        btn.setTitleColor(.rgba(132, 132, 132, 1), for: .normal)
        btn.titleLabel?.font = .regular(14)
        //btn.addTarget(self, action: #selector(editResumeInf), for: .touchUpInside)
        return btn
    }()
    
    private lazy var workLab:UILabel = {
        let tw = UILabel()
        tw.text = ""//本科·专业专业"
        tw.textColor = .rgba(132, 132, 132, 1)
        tw.font = .regular(14)
        return tw
    }()
    private lazy var Lab:UILabel = {
        let tw = UILabel()
        tw.text = ""//师承人"
        tw.textColor = .rgba(132, 132, 132, 1)
        tw.font = .regular(14)
        return tw
    }()
    private lazy var sLab:UILabel = {
        let tw = UILabel()
        tw.text = ""//在校经历："
        tw.textColor = .rgba(132, 132, 132, 1)
        tw.font = .regular(14)
        return tw
    }()
    private lazy var contentLab:UITextView = {
        let tw = UITextView()
        tw.text = ""//在大学，没有一个明确的学习目标是不行的，那样会 让自己在学习的路途上迷失自己。所以我就为自己制定了很多短期的目标和一个最终目标。我让自己能"
        tw.textColor = .rgba(132, 132, 132, 1)
        tw.font = .regular(14)
        tw.isEditable = false
        tw.isScrollEnabled = false
        return tw
    }()

    private lazy var line:UIView = {
        let line = UIView()
        line.backgroundColor = .rgba(238, 238, 238, 1)
        return line
        
    }()
}
